修复Linux双网卡无法打通外网,配置默认路由 您所在的位置:网站首页 双网卡 ping 修复Linux双网卡无法打通外网,配置默认路由

修复Linux双网卡无法打通外网,配置默认路由

2023-11-24 03:15| 来源: 网络整理| 查看: 265

今天遇到本地虚机的怪问题,内网访问登录响应慢,而且登陆后无法使用外网进行yum安装。(虚机配置了双网卡进行内外网的连接)。

登陆后查看网卡状态,看着正常但无法ping通外网(114.114.114.114)

[root@OEL612C ~]# ifconfig -a eth0 Link encap:Ethernet HWaddr 08:00:27:E2:F6:9A inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fee2:f69a/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:3 errors:0 dropped:0 overruns:0 frame:0 TX packets:13 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:790 (790.0 b) TX bytes:1255 (1.2 KiB) eth1 Link encap:Ethernet HWaddr 08:00:27:88:EF:3B inet addr:192.168.56.62 Bcast:192.168.56.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe88:ef3b/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:71 errors:0 dropped:0 overruns:0 frame:0 TX packets:73 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:8742 (8.5 KiB) TX bytes:9271 (9.0 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

这种问题一般都是出在本地路由错乱上,一看路由果然有问题

[root@OEL612C ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.56.1 0.0.0.0 UG 0 0 0 eth1 10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1 192.168.56.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1

内网网卡成默认路由了,用命令修改外网网卡为默认路由

[root@OEL612C ~]# route del -net 0.0.0.0 [root@OEL612C ~]# route add -net 0.0.0.0/0 gw 10.0.2.2 netmask 0.0.0.0 dev eth0 [root@OEL612C ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.0.2.2 0.0.0.0 UG 0 0 0 eth0 10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1 192.168.56.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1

然后成功可以使用yum安装外网软件,内网也能正常工作

[root@OEL612C ~]# yum list gcc Loaded plugins: ulninfo Available Packages gcc.x86_64 4.4.7-23.0.1.el6 public_ol6_latest

可是一重启,默认路由就又变回内网网卡了! 使用最简方法处理重启失效问题:往rc.local里写命令,注意文件要有运行权限。

echo "route del -net 0.0.0.0 route add -net 0.0.0.0/0 gw 10.0.2.2 netmask 0.0.0.0 dev eth0" >> /etc/rc.local chmod +x /etc/rc.local

轻松搞定。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有